<?php 

	// Filters for many2many talbes
	echo '<p id="m2mfilters_title">Дополнительная фильтрация: </p>';
	echo '<table id="m2mfilters">';
	$table = new Crud_Db_Table($this->request['table']);
	foreach ($table->getMany2ManyTables() as $m2m) {
		$column3rd = $m2m->getFKColumnNotFor($table);
		if (!$column3rd->isFK()) {
			continue;
		}
		
		$element = Crud_Form_Element::factory($column3rd)->getElement();
		if (!$element instanceof Zend_Form_Element_Multi) {
			continue;
		}
		
		// Set options for select
		$options = $element->getMultiOptions();
		if (isset($options[''])) unset($options['']);
		if (!$options) {
			continue;
		}
		
		$element->clearMultiOptions();
		$element->addMultiOption(0, 'Не фильтровать');
		$element->addMultiOptions($options);
		
		
		$element->setAttrib('class', 'search');
		$element->setAttrib('default', 0);
		$element->setBelongsTo('m2msearch');
		
		$element->setDecorators(array(
			'ViewHelper',
		    array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class'  => 'm2mfilters_container')),
        	array('Label', array('tag' => 'td', 'class' => 'm2mfilters_label')),
        	array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        ));
        
        // Set label for search column
		$table3rd = $column3rd->getFKTable();
		if ($table3rd->getConfig() && $table3rd->getConfig()->label) {
			$element->setLabel($table3rd->getConfig()->label);
		}
		
		$element->setName($m2m->getTableName() . '__' . $element->getName());
		echo $element;
	}
	echo '</table>';
	
	